<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

<h1>测试axios发出异步请求</h1>

<input type="button" value="请求" onclick="fn()">

<input type="button" value="post请求" onclick="postfn()">

<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
<script>
    function postfn(){
        //创建FormData对象，把数据添加到对象中
        let data = new FormData();
        data.append("info","xyz");
        //发起post异步请求
        axios.post("/helloAxios",data).then(function (response) {
            alert(response.data);
        })
    }

   function fn(){
       //发起异步get请求
      /* axios.get("/helloAxios").then(function (response) {
           //请求成功后执行的代码，response代表响应对象
           alert(response.data);//response.data:响应数据
       }).catch(function (err) {
           //请求失败时执行的代码，err代表错误对象
           alert(err);
       })*/

       axios.get("/helloAxios?info=abc").then(function (response) {
           //请求成功后执行的代码，response代表响应对象
           alert(response.data);//response.data:响应数据
       })
   }
</script>


</body>
</html>